/**
 * 
 */
package com.nwpusp.model;

import java.io.Serializable;
import java.util.ArrayList;

import com.nwpusp.jni.JniProxy;
import com.nwpusp.model.location.*;

/**
 * @author JustinCao
 *
 */

public abstract class Entity implements Cloneable, Serializable{

	public final static int ENTITYSTS_Normal = 0;
	
	static {
		System.loadLibrary("PetsSports");
	}
	@Override
	public Object clone() {
		Object o = null;
		try {
			o = super.clone();
			((Entity)o).position = (Axis)(position.clone());
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return o;
	}

	private int status = ENTITYSTS_Normal;
	private Axis position = new Axis(0, 0, 0);
	private Size size = new Size(0, 0, 0);
	
	
	
	synchronized public Axis getPosition() {
		return position;
	}
	
	synchronized public void setPosition(Axis position) {
		this.position = position;
	}
	
	public Size getSize() {
		return size;
	}
	
	public void setSize(Size size) {
		this.size = size;
	}
	
	public int getStatus() {
		return status;
	}
	
	public void setStatus(int status) {
		this.status = status;
	}
	
	public boolean isCollide(Entity target) {
		int[] pa = position.getIntArray();
		int[] pb = target.position.getIntArray(); 
		int[] sa = size.getIntArray(); 
		int[] sb = target.size.getIntArray();
		return JniProxy.isCollid(pa, pb, sa, sb);
		//Size targetSize = target.getSize();
		//Size thisSize = getSize();
		//if(thisSize.getX() > targetSize.getX() && thisSize.getY() > targetSize.getY() && thisSize.getZ() > targetSize.getZ()) {
		//	collideJudgeByMe(target);
		//}
		//return target.collideJudgeByMe(this);
	}
	
	//private boolean collideJudgeByMe(Entity target) {
	//	ArrayList<Axis> vertex = target.getVertex();
	//	for(Axis v : vertex) {
	//		if(isAxisInMyBody(v)) {
	//			return true;
	//		}
	//	}
	//	return false;
	//}
	
	//private boolean isAxisInMyBody(Axis v) {
	//	Axis polar = (Axis)position.clone();
	//	polar.Move(size);
	//	return (   position.getX() < v.getX() && position.getY() < v.getY() && position.getZ() < v.getZ()
	//			&& polar.getX() > v.getX() && polar.getY() > v.getY() && polar.getZ() > v.getZ());
	//}

	//private ArrayList<Axis> getVertex() {
	//	ArrayList<Axis> vertex = new ArrayList<Axis>(8);
		//	vertex.add(((Axis) position.clone()).Move(0, 0, 0));
	//	vertex.add(((Axis) position.clone()).Move(0, 0, size.getZ()));
	//	vertex.add(((Axis) position.clone()).Move(0, size.getY(), 0));
	//	vertex.add(((Axis) position.clone()).Move(0, size.getY(), size.getZ()));
	//	vertex.add(((Axis) position.clone()).Move(size.getX(), 0, 0));
	//	vertex.add(((Axis) position.clone()).Move(size.getX(), 0, size.getZ()));
	//	vertex.add(((Axis) position.clone()).Move(size.getX(), size.getY(), 0));
	//	vertex.add(((Axis) position.clone()).Move(size.getX(), size.getY(), size.getZ()));
	//	return vertex;
	//}
}
